package edu.suda.xsap.controller;

import edu.suda.xsap.common.Result;
import edu.suda.xsap.dto.ScheduleRecordDto;
import edu.suda.xsap.dto.convert.ScheduleRecordConvert;
import edu.suda.xsap.entity.ScheduleRecord;
import edu.suda.xsap.service.ScheduleRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RestController
@RequestMapping("/schedule")
@Slf4j
public class ScheduleRecordController {

    @Autowired
    ScheduleRecordService scheduleRecordService;

    @GetMapping("/list")
    public Result list() {
        List<ScheduleRecordDto> scheduleRecordDtos = scheduleRecordService.findAll();
        return Result.success(scheduleRecordDtos);
    }

    @GetMapping("/find/{id}")
    public Result get(@PathVariable("id") Integer id) {
        ScheduleRecordDto scheduleRecordDto = scheduleRecordService.findById(id);
        return Result.success(scheduleRecordDto);
    }

    @PostMapping("/add")
    public Result save(@RequestBody ScheduleRecord scheduleRecord) {
        log.info("save scheduleRecord: " + scheduleRecord);
        scheduleRecordService.save(scheduleRecord);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody ScheduleRecord scheduleRecord) {
        scheduleRecordService.update(scheduleRecord);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        scheduleRecordService.delete(id);
        return Result.success();
    }
}
